<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>我的预约(经纪人)</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../../../taofang/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
    <link rel="stylesheet" href="../../../taofang/css/TenantCentre.css">
    <link rel="stylesheet" href="../../../taofang/css/home.css">
</head>
<body>
<script src="../../../taofang/plugins/jquery-3.4.1.js"></script>
<script src="../../../taofang/plugins/bootstrap-3.3.7-dist/js/bootstrap.js"></script>

<%@include file="topB.jsp"%>



<div class="col-md-9 zy3">
    <table class="table table-hover">
        <thead>
        <tr>
            <th>预约人姓名</th>
            <th>预约人电话</th>
            <th>房源编号</th>
            <th>预约状态</th>
            <th>预约日期</th>
            <th>当天时间段</th>
            <th>是否确认</th>
        </tr>
        </thead>
        <tbody id="tb">
        <c:forEach items="${appointmentTime}" var="a" varStatus="loop">

            <tr>
                <td style="display: none">${a.id}</td>
                <td>${tenant[loop.count-1].name}</td>
                <td>${tenant[loop.count-1].phone}</td>
                <td>${a.houseId}</td>
                <td name="state" style="color: red">${a.appointmentState}</td>
                <td><fmt:formatDate value="${a.appointmentDate}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
                <td>${a.timeQuantum}</td>
                <td><button type="button" class="btn btn-success" onclick="changetrue(this,${a.id})">确认</button>&nbsp;&nbsp;
                    <button type="button" class="btn btn-danger" onclick="changefalse(this,${a.id})">取消</button></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<%@include file="BottomB.jsp"%>

<script>
    $(function () {
        let state = document.getElementsByName("state")
        for (let i = 0; i <state.length;i++) {
            let statetext = state[i].innerText;
            if (statetext != "审核中"){
                let tr = state[i].parentElement;
                let td3 = $(tr).find('td').eq(7)
                td3.text("")
            }
        }

    })

    function changetrue(obj,id) {
        let tr = obj.parentElement.parentElement;
        let td4 = $(tr).find('td').eq(4)
        let td=$(tr).find('td').eq(7)
        let data = {"id":id}
        $.post('/taofang/Appointment/changeTrue.action', data, function (data) {
            if (data.code==200){
                let td44 = td4.text("预约成功")
                td.text("")
            }else{
                alert("确认失败")
            }

        })
    }


    function changefalse(obj,id) {
        let tr = obj.parentElement.parentElement;
        let td4 = $(tr).find('td').eq(4)
        let td=$(tr).find('td').eq(7)
        let data = {"id":id}
        $.post('/taofang/Appointment/changeFalse.action', data, function (data) {
            if (data.code==200){
                let td44 = td4.text("预约失败")
                td.text("")
            }else{
                alert("取消失败")
            }

        })


    }

</script>


</body>
</html>